﻿cmake_minimum_required(VERSION 3.14)

project(DMDFaceProjector_App VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(RC_ICONS "./Resources/images/logo.png")

# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check https://doc.qt.io/qt/deployment-android.html for more information.
# They need to be set before the find_package(...) calls below.

if(ANDROID)
    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
endif()

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick Qml Concurrent Svg Widgets LinguistTools SerialPort Network REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick Qml Concurrent Svg Widgets LinguistTools SerialPort Network REQUIRED)

if(ANDROID)
    find_package(Qt${QT_VERSION_MAJOR} COMPONENTS androidextras REQUIRED)
    #添加宏定义
    add_definitions(-DQ_ANDROID_CONTENT_DEVICE_EXPORT)
    message("android!!")
endif()



add_definitions(-DQT_QUICK_CONTROLS_STYLE)
set(QT_QUICK_CONTROLS_CONF ":/qml/qtquickcontrols2.conf")


# sources
# ******************************************************************************
message("CMAKE_CURRENT_SOURCE_DIR:sssssssss:" ${CMAKE_CURRENT_SOURCE_DIR})
message("ROOT_DIR:sssssssss:" ${ROOT_DIR})
include_directories(${ROOT_DIR}/libs/common)

AddSources("${CMAKE_CURRENT_SOURCE_DIR}/src" "Src" list_app_src)
AddResources("${CMAKE_CURRENT_SOURCE_DIR}/Resources/qml" "Qml" list_qml_src)
AddResourcesQRC("${CMAKE_CURRENT_SOURCE_DIR}" "Resources" list_Resources_src)


LINK_DIRECTORIES(                                  #相关库文件的目录
    ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}
)


#get_property( dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES )

#foreach( dir ${dirs} )
#    message( STATUS "include dir=${dir}" )
#endforeach()

#add_subdirectory(${ROOT_DIR}/${PROJECT_NAME})
message("SSSS:${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")



set(UI_PATH
    #${PROJECT_SOURCE_DIR}/Resources/${PROJECT_NAME}.rc
    )
message("SB:" +${ROOT_DIR})
# target
# ******************************************************************************
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(ALL_SOURCES
    ${list_app_src}
    ${list_Resources_src}
    ${list_qml_src}
    ${UI_PATH}
    )


set(FILES_PATH
    ${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules
    )



if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(${PROJECT_NAME}
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
    message("------------------Qt6")
    qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
else()
    if(ANDROID)
        add_library(${PROJECT_NAME} SHARED
            ${ALL_SOURCES}
        )
    else()
        add_executable(${PROJECT_NAME}
          ${ALL_SOURCES}
        )
    endif()

    qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()


target_compile_definitions(${PROJECT_NAME}
  PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
#target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_INCLUDE})

target_link_libraries(${PROJECT_NAME}
  PRIVATE Qt${QT_VERSION_MAJOR}::Core 
  Qt${QT_VERSION_MAJOR}::Widgets
  Qt${QT_VERSION_MAJOR}::Svg
  Qt${QT_VERSION_MAJOR}::Quick 
  Qt${QT_VERSION_MAJOR}::Qml
  Qt${QT_VERSION_MAJOR}::SerialPort
  Qt${QT_VERSION_MAJOR}::Network
  Qt${QT_VERSION_MAJOR}::Concurrent  
  common.lib
  )
if(ANDROID)
    target_link_libraries(${PROJECT_NAME}
      PRIVATE Qt${QT_VERSION_MAJOR}::AndroidExtras 
      )
    message("android!!")
endif()


set_target_properties(${PROJECT_NAME} PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_import_qml_plugins(${PROJECT_NAME})
    qt_finalize_executable(${PROJECT_NAME})
endif()


